﻿using System.Diagnostics;
using Microsoft.AspNetCore.Mvc;
using Demo.Models;

namespace Demo.Controllers;

public class HomeController : Controller
{
    private readonly ILogger<HomeController> _logger;
    private readonly MyDbContext _context;
    public HomeController(ILogger<HomeController> logger, MyDbContext context)
    {
        _logger = logger;
        _context = context;
    }

    public IActionResult Index()
    {
        var s1 = new Student { Name = "郭靖" };
        var s2 = new Student { Name = "黄蓉" };
        var s3 = new Student { Name = "穆念慈" };

        var t1 = new Teacher { Name = "江南七怪" };
        var t2 = new Teacher { Name = "欧阳锋" };
        var t3 = new Teacher { Name = "洪七公" };
        var t4 = new Teacher { Name = "黄老邪" };


        //s1.Teachers.Add(t1);
        //s1.Teachers.Add(t3);

        //s2.Teachers.Add(t3);
        //s2.Teachers.Add(t4);

        //s3.Teachers.Add(t3);
        //s3.Teachers.Add(t4);

        //_context.Students.Add(s1);
        //_context.Students.Add(s2);
        //_context.Students.Add(s3);

        //_context.Teachers.Add(t1);
        //_context.Teachers.Add(t2);
        //_context.Teachers.Add(t3);

        //_context.SaveChanges();

        //_context.SavedChanges += _context_SavedChanges;

      //  var gj = _context.Students.Where(x=>x.Id==1).ToList();

       


        return View();
    }

    private void _context_SavedChanges(object? sender, Microsoft.EntityFrameworkCore.SavedChangesEventArgs e)
    {
        
    }

    public IActionResult Privacy()
    {
        return View();
    }

    [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
    public IActionResult Error()
    {
        return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
    }
}
